﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using VioletDevelopmentLaboratory.Net.Web;

public partial class vboard_webmanager_user_role : VioletDevelopmentLaboratory.Net.Web.PageBase
{
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!Roles.Enabled)
		{
			RoleDisablePanel.Visible = true;
			RoleManagerPanel.Visible = !RoleDisablePanel.Visible;
			return;
		}

		if (!Page.IsPostBack)
		{
			Roles_DataBind();
		}
	}

	protected void Roles_DataBind()
	{
		string[] roles = Roles.GetAllRoles();

		RolesDropDownList.DataSource = roles;
		RolesDropDownList.DataBind();
	}
	protected void AddButton_Click(object sender, EventArgs e)
	{
		if (Page.IsValid)
		{
			if (Roles.RoleExists(RoleNameTextBox.Text))
			{
				VUtility.ShowMessagePanel(Page, RoleNameTextBox.Text + " 역할이 이미 존재합니다.", true);
				return;
			}

			Roles.CreateRole(RoleNameTextBox.Text);
			Roles_DataBind();
			RoleNameTextBox.Text = "";

			VUtility.ShowMessagePanel(Page, RoleNameTextBox.Text + " 역할이 추가되었습니다.", true);
		}
	}
	protected void RemoveButton_Click(object sender, EventArgs e)
	{
		if (Page.IsValid)
		{
			if (!Roles.RoleExists(RolesDropDownList.SelectedValue))
			{
				VUtility.ShowMessagePanel(Page, "역할이 존재하지 않습니다.", true);
				return;
			}

			Roles.DeleteRole(RolesDropDownList.SelectedValue, false);
			Roles_DataBind();

			VUtility.ShowMessagePanel(Page, "역할이 제거되었습니다", true);
		}
	}
}
